package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectPersonnelListener;
import com.longxi.tianjintianbao.model.Personnel;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class PersonnelViewBinder extends ItemViewBinder<Personnel, PersonnelViewBinder.ViewHolder> {
    SelectPersonnelListener listener;

    public PersonnelViewBinder(SelectPersonnelListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_personnel, parent, false);
        return new ViewHolder(root);
    }

    

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Personnel personnel) {
        holder.mTvUsername.setText(personnel.getUsername());

        if(personnel.isSelect()){
            holder.mIvSelect.setImageResource(R.mipmap.ic_select_press);
        }else{
            holder.mIvSelect.setImageResource(R.mipmap.ic_select_normal);
        }

        holder.mTvWorkState.setText(personnel.getDept());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSelectPersonnel(personnel, holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout mLlBtn;
        TextView mTvUsername;
        TextView mTvWorkState;
        ImageView mIvSelect;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvUsername = itemView.findViewById(R.id.tvUsername);
            mTvWorkState = itemView.findViewById(R.id.tvWorkState);
            mIvSelect = itemView.findViewById(R.id.ivSelect);
        }
    }


}
